const cloud = require('wx-server-sdk')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })
const db = cloud.database()
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  return await db.collection('user').add({
    data: {
      openid: wxContext.OPENID,
      nickName: event.nickName,
      gender: event.gender,
      language: event.language,
      city: event.city,
      province: event.province,
      country: event.country,
      avatarUrl: event.avatarUrl,
      role: "user"
    },
  })
}